package com.bob.clan.wxconnector.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * 由于@ServerEndpoint是Java EE的注解，Spring Boot不会自动扫描它，因此我们需要手动注册这个Endpoint。
 * 之所以加条件，是因为开发环境是idea集成的tomcat，没有ws容器，而生产环境是tomcat+war的方式进行，tomcat已包含ws的容器，所以不需要注入
 */
@ConditionalOnProperty(name = "spring.profiles.active", havingValue = "dev")
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {

    }
}